package com.color.admin.system.repository;


import com.color.admin.system.entity.SysMenu;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Set;

/**
 * @author HaiQiu
 * @date 2021/12/23
 */
@Repository
public interface MenuRepository extends JpaRepository<SysMenu,String>, JpaSpecificationExecutor<SysMenu> {

    /**
     * 批量删除菜单
     * @param ids 菜单权限ID
     * @return 成功条数
     */
    int deleteAllByIdIn(Set<String> ids);

    /**
     * 根据菜单名称查询菜单
     * @param menuName 名称
     * @return 菜单
     */
    List<SysMenu> findSysMenuByMenuName(String menuName);

    /**
     * 根据菜单父级ID查询菜单
     * @param parentId 父级ID
     * @return 菜单集合
     */
    List<SysMenu> findSysMenuByParentId(String parentId);

    /**
     * 批量删除菜单和角色绑定关联
     * @param menuIds 菜单ID
     */
    @Modifying
    @Query(value = "delete from sys_roles_menus where menu_id in (?1)",nativeQuery = true)
    void deleteRolesMenusByMenuIds(Set<String> menuIds);
}
